package be.ipl.finito.util;

import java.security.Key;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

public final class Util {
	public static void checkObject(Object o) {
		if (o == null)
			throw new NullPointerException();
	}

	public static void checkString(String s) {
		checkObject(s);
		if (s.trim().equals(""))
			throw new IllegalArgumentException();
	}

	public static void checkNegativeOrZero(double d) {
		if (d > 0.0)
			throw new IllegalArgumentException();
	}

	public static void checkPositiveOrZero(double d) {
		if (d < 0)
			throw new IllegalArgumentException();
	}

	public static void checkPositive(double d) {
		if (d <= 0.00001)
			throw new IllegalArgumentException();
	}

	public static void checkPositive(int i) {
		if (i <= 0)
			throw new IllegalArgumentException();
	}

	public static String encrypt(String password) {
		try {
			String key = "blob";
			Key clef = new SecretKeySpec(key.getBytes("ISO-8859-2"), "Blowfish");
			Cipher cipher = Cipher.getInstance("Blowfish");
			cipher.init(Cipher.ENCRYPT_MODE, clef);
			return new String(cipher.doFinal(password.getBytes()));
		} catch (Exception e) {
			return null;
		}
	}
}
